#ifndef _TEST_
#define _TEST_

#include"util.hpp"

class Test
{
public:
    static void test_json()
    {
        // 序列化
        Json::Value v1;
        std::string s1;
        v1["name"].append(123);
        v1["password"]=123321;
        v1["path"][5]=132;
        Json_Util::serialize(v1,s1);
        std::cout<<s1<<std::endl;
    
        // 反序列化
        std::string s2;
        Json::Value v2;
        // R"(...)":避免转义字符
        s2+=R"({ "name":"lisi", "password":123321, "path":"/root/usr" })";
        Json_Util::unserialize(s2,v2);
        std::cout<<v2<<std::endl;
    }
    
    static void test_log()
    {
        INF_LOG("测试日志INF");
        ERR_LOG("测试日志ERR");
        DBG_LOG("测试日志DBG");
    }
    
    static void test_stringsplit()
    {
        std::string s,sep;
        std::vector<std::string> v;
        s+="hello  world ! nihao   shijie  !";
        sep+=' ';
        String_Util::split(s,sep,v);
        for(auto e:v)
        {
            std::cout<<e<<std::endl;
        }
    }
    
    static void test_fileread()
    {
        std::string s;
        File_Util::read("test",s);
        std::cout<<s<<s.size()<<std::endl;
    }

    static void test_mysql()
    {
        std::string host="127.0.0.1";
        std::string user="zhy";
        std::string pass="1452517351";
        std::string name="gobang_online";
        uint16_t port=3306;
        MYSQL* mysql=Mysql_Util::mysql_create(host,user,pass,name,port);
        std::string mysql_table_query=
        "insert into user (name,account,password) values "
        "('赵六','123321','zhaoliu123123')";
        Mysql_Util::mysql_exec(mysql,mysql_table_query);
        Mysql_Util::mysql_destroy(mysql);
    }
};

#endif